package com.gantzgulch.generics;

/**
 * This class does not demonstrate generics, but it is used by some of the classes that do demonstrate generics. 
 *
 */
public class Objects {

    /**
     * Calculates the hash code of an object returning 0 when the object is <code>null</code>.
     * 
     * @param object the object to calculate the hash code of, may be <code>null</code>
     * @return the hash code of the object, or 0 if <code>null</code>
     */
	public static int hashCode(Object object) {
		return object != null ? object.hashCode() : 0;
	}
	
	/**
	 * Compares two objects for equality, allowing for one or both objects to be <code>null</code>.
	 * 
	 * @param o1 the first object to compare, may be <code>null</code>
	 * @param o2 the second object to compare, may be <code>null</code>
	 * @return <code>true</code> if the objects are equal
	 */
	public static boolean equals(Object o1, Object o2){
		
	 	if( o1 == o2 ){
    		return true;
    	}
    	
    	if( o1 == null || o2 == null ){
    		return false;
    	}
    	
    	return o1.equals(o2);
	}
	
	public static RuntimeException ensureRuntimeException(Throwable t){
		if( t instanceof RuntimeException){
			return (RuntimeException)t;
		}
		return new RuntimeException(t);
	}
}
